package cn.edu.xjtu.nbrash.xbarsuite.zxingdemo;

import java.util.HashMap;
import java.util.Map;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import cn.edu.xjtu.nbrash.xbarsuite.R;

public class ZXingDemo extends ListActivity {

	private String[] items;
	private Map<String, Intent> intents;

	private void initIntentsMap() {
		intents = new HashMap<String, Intent>();

		this.putInIntents(R.string.title_activity_rash_encode,
				RashEncodeDemoActivity.class);

		this.putInIntents(R.string.title_activity_rash_scan,
				RashScanActivity.class);

		this.putInIntents(R.string.title_activity_scan_from_image,
				ScanFromImageActivity.class);
	}

	private void putInIntents(int rsid, Class<?> cls) {
		intents.put(getString(rsid), new Intent(this, cls));
	}

	public void onListItemClick(ListView parent, View v, int position, long id) {
		startActivity(intents.get(items[position]));
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_zxing_demo);

		initIntentsMap();
		items = intents.keySet().toArray(new String[0]);
		setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, items));
	}

}
